package com.lang.runtime;

import java.io.File;
import java.lang.Exception;
import java.lang.Process;
import java.lang.Runtime;
import java.lang.String;

/**
 * <pre>
 * {@link #executeBat(String, String)}的实际应用场景:
 * 在一个java程序通过bat启动另外一个java程序
 * 如:在java管理后台程序,启动java游戏服务器
 * </pre>
 * @author Ackles
 */
public class RuntimeDemo {
	private static final String BAT_DIR = "E:/work/zc/cf/server/server_tw_dev/centerserver";
	private static final String BAT = "launcher.bat";
	
	public static void main(String[] args) {
		executeBat(BAT, BAT_DIR);
	}

	/**
	 * 在另外一个进程执行bat
	 * @param batName
	 * @param batDir
	 * @return
	 */
	public static boolean executeBat(String batName, String batDir) {
		try {
			String command = "cmd /c start " + batName;
			File dir = new File(batDir);
			Process process = Runtime.getRuntime().exec(command, null, dir);
			return 0 == process.waitFor();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
}
